package com.future;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 * 异步调用：runAsync
 *
 * <p>
 *
 * @author xinder
 */
public class CompletableFutureDemo {

	public static void main(String[] args) throws ExecutionException, InterruptedException {
		// 发起一个请求，没有返回值的runAsync异步回调
		CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
			try {
				// TimeUnit.SECONDS.sleep(2);  //阻塞
				// int a = 1 / 0;
				System.out.println("1211111");
			} catch (Exception e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName() + "   runAsync");
		});
		System.out.println("sdfsdfsdf");
		TimeUnit.SECONDS.sleep(3);
		// System.out.println(completableFuture.get());
		//
		// System.out.println(completableFuture.join());
		//
		// System.out.println("完成");

	}
}
